package com.woniu.mapper;

import com.woniu.been.entity.Exam;
import com.woniu.been.entity.Users;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UsersMapper {

//    @Select("SELECT * FROM users ")
    List<Users> findAll(Users users);
    //登录逻辑根据用户名和密码查询用户
    @Select("SELECT * FROM users WHERE username=#{username} AND password=#{password}")
    Users login(@Param("username") String username,@Param("password") String password);

    void register(Users users);

    //根据phone查询用户
    @Select("SELECT * FROM users WHERE phone= #{phone}")
    Users findByPhone(String phone);
void update(Users users);

    @Insert("INSERT INTO exam(topic,fenshu,maxfenshu,user,userId) VALUES(#{topic},#{fenshu},#{maxfenshu},#{user},#{userId})")
    void addexam(Exam exam);
    @Update("<script>" +
            "update users " +
            "<set>" +
            "  <if test='username != null and username != \"\"'>username=#{username},</if>" +
            "  <if test='password != null and password != \"\"'>password=#{password},</if>" +
            "  <if test='phone != null and phone != \"\"'>phone=#{phone},</if>" +
            "  <if test='points != null'>points=#{points},</if>" +
            "</set>" +
            "where user_id=#{userId}" +
            "</script>")
    void updateById(Users user);

    @Delete("DELETE FROM users WHERE user_id=#{userId}")
    void deleteById(Integer userId);

    @Select("SELECT * FROM users WHERE user_id= #{userId}")
    Users findById(Integer userId);
}
